<%
	var Connection=new Class.create();
		Connection.prototype=
		{
			initialize:function($options)
			{
				this.object=Server.CreateObject('ADODB.Connection');
				if(arguments.length!=0)
				{		
					if(typeof($System)!='undefined') 
						$options=($options||$System.connection);
					else
						$options=($options||{});
					
					/* 声明属性 */
					this.provider=String.interpret($options.provider).toLowerCase();
					this.parameters=$options.parameters;
					this.otherparameters=$options.otherparameters;	
					this.connectionstring=$options.connectionstring;												
					this.name=($options.name||'');
					this.isopen=($options.isopen==false ? false:true);
					
					if(this.provider=='Provider error') throw 'Provider error';
					if(this.parameters==undefined) throw 'Parameters error';
					
					/* 构造对象 */
					try
					{													
						var tempText='',tempObject={};
						switch($options.provider)
						{
							case 'driver:access':
								tempObject=
								{
									dbq:this.parameters.dbq,
									uid:(this.parameters.uid||'admin'),
									pwd:this.parameters.pwd
								};
								this.connectionstring=cusDataBaseProvider_DriverAccess.interpolate(tempObject);							
								break;
							case 'driver:sqlserver':							
								tempObject=
								{
									server:this.parameters.server,
									uid:this.parameters.uid,
									pwd:this.parameters.pwd,
									database:this.parameters.database
								};
								this.connectionstring=cusDataBaseProvider_DriverSqlserver.interpolate(tempObject);						
								break;							
							case 'jet':								
								tempObject=
								{
									datasource:this.parameters.datasource,
									userid:(this.parameters.userid||'admin'),
									password:(this.parameters.password||''),
									databasePassword:(this.parameters.databasePassword||'')
								};							
								this.connectionstring=cusDataBaseProvider_Jet.interpolate(tempObject);						
								break;
							case 'sqloledb':							
								tempObject=
								{
									server:this.parameters.server,
									uid:this.parameters.uid,
									pwd:this.parameters.pwd,
									database:this.parameters.database
								};							
								this.connectionstring=cusDataBaseProvider_Sqlserver.interpolate(tempObject);
								break;
							case 'odbc':
								break;
							case 'oracle':
								break;
							case 'custom':
								if(this.connectionstring==undefined) throw 'ConnectionString error';
								break;		
							default:
								throw 'Provider error';
						}
												
						this.object.connectionstring=this.connectionstring;
						if(this.otherparameters!=undefined) 
						{
							if(Object.varType(this.otherparameters)=='string')
								this.object.connectionstring+=this.otherparameters;
							else if(Object.varType(this.otherparameters)=='array')
								this.object.connectionstring+=this.otherparameters.join('');
							else
								throw 'Otherparameters error';
						}						
						//alert(tempText)
						if(this.isopen==true) this.object.Open();	
					}
					catch(e)
					{
						if(e=='Provider error')
							throw new Error(cusErrors_0001_ADO$Connection);
						else if(e=='Parameters error')
							throw new Error(cusErrors_0002_ADO$Connection);	
						else if(e=='Otherparameters error')
							throw new Error(cusErrors_0003_ADO$Connection);	
						else if(e=='ConnectionString error')
							throw new Error(cusErrors_0004_ADO$Connection);
						else
						{
							if(e!=cusFrameworkDo$Break&&Object.varType(e)!='string')							
								throw e;
							else
								throw new Error(e);							
						}					
					}
				}
			},
			properties:function()
			{
				return this.object.Properties;
			},
			errors:function()
			{
				return this.object.Errors;
			},			
			get:function($property)
			{
				if(($property in this.object)==false)		
					throw new Error(cusErrors_0099_ADO$Global);
					
				$property=($property.toLowerCase());
				if($property in this.object) this[$property]=this.object[$property];				
				return this.object[$property];
			},			
			set:function($property,$value)
			{
				if(($property in this.object)==false)
					throw new Error(cusErrors_0099_ADO$Global);
					
				$property=($property.toLowerCase());				
				this[$property]=$value;
				return this.object[$property]=$value;
			},	
			beginTrans:function()
			{
				this.object.BeginTrans();
			},
			commitTrans:function()
			{
				this.object.CommitTrans();
			},
			rollbackTrans:function()
			{
				this.object.RollbackTrans();
			},
			cancel:function()
			{
				this.object.Cancel();
			},
			execute:function($commandText,$records,$options)
			{
				if($commandText==undefined) throw new Error(cusErrors_0005_ADO$Connection);
				return this.object.Execute($commandText,$records,$options);
			},				
			open:function($cString,$userid,$password,$options)
			{
				if($cString==undefined) throw new Error(cusErrors_0006_ADO$Connection);
				this.object.open($cString,$userid,$password,$options);
			},
			openSchema:function($queryType,$criteria,$schemaID)
			{
				return this.objec.OpenSchema($queryType,$criteria,$schemaID);
			},
			close:function()
			{
				try
				{
					this.object.Close();
					for(var iProperty in this)
						this[iProperty]=null;					
				}
				catch(e)
				{}
			}
		};
%>